define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {
    if(Config.ids == '' || Config.ids == null){
        Config.ids = 0;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionorderquantityp/index/?ids=' + Config.ids,
                    add_url: 'feditionorderquantityp/add',
                    edit_url: 'feditionorderquantityp/edit',
                    del_url: 'feditionorderquantityp/del',
                    multi_url: 'feditionorderquantityp/multi',
                    import_url: 'feditionorderquantityp/import',
                    table: 'fedition_orderquantity',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        // {field: 'order_id', title: __('Order_id'), operate: 'LIKE'},
                        // {field: 'product_id', title: __('Product_id'), operate: 'LIKE'},
                        {field: 'material', title: __('商品价格'), operate: false},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'quantity', title: __('Quantity'), operate: 'LIKE'},
                        {field: 'variant_title', title: __('Variant_title'), operate: 'LIKE'},
                        //{field: 'sku', title: __('Sku'), operate: 'LIKE'},
                        //{field: 'variant_id', title: __('Variant_id'), operate: 'LIKE'},
                        // {field: 'material', title: __('变体价格'), operate: 'LIKE'},
                        //{
                        //    field: 'buttons',
                        //    width: "120px",
                        //    title: __('该商品SKU库'),
                        //    table: table,
                        //    events: Table.api.events.operate,
                        //    operate: false,
                        //    buttons: [
                        //        {
                        //            name: 'detail',
                        //            text: __('该商品SKU库'),
                        //            title: __('该商品SKU库'),
                        //            extend: 'data-area=\'["90%","90%"]\'',
                        //            classname: 'btn btn-sm btn-success btn-dialog',
                        //            icon: 'fa fa-try fa-fw',
                        //            url: 'feditionorderskup/index?product_id={product_id}'
                        //        }
                        //    ],
                        //    formatter: Table.api.formatter.buttons
                        //},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        doubt: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionorderquantityp/doubt',
                    add_url: 'feditionorderquantityp/add',
                    edit_url: 'feditionorderquantityp/edit',
                    del_url: 'feditionorderquantityp/del',
                    multi_url: 'feditionorderquantityp/multi',
                    import_url: 'feditionorderquantityp/import',
                    table: 'fedition_orderquantity',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        // {field: 'order_id', title: __('Order_id'), operate: 'LIKE'},
                        // {field: 'product_id', title: __('Product_id'), operate: 'LIKE'},
                        //{field: 'accounturl_name', title: __('店铺'), operate: false},
                        //{field: 'admin_name', title: __('店铺管理人'), operate: false},
                        {field: 'image', title: __('商品主图'), formatter: Table.api.formatter.image, events: Table.api.events.image},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        // {field: 'quantity', title: __('Quantity'), operate: 'LIKE'},
                        {field: 'variant_title', title: __('Variant_title'), operate: 'LIKE'},
                        // {field: 'sku', title: __('Sku'), operate: 'LIKE'},
                        //{field: 'variant_id', title: __('Variant_id'), operate: 'LIKE'},
                        // {field: 'material', title: __('变体价格'), operate: 'LIKE'},
                        {field: 'material', title: __('变体价格'),editable: true, operate: false},
                        //{
                        //    field: 'buttons',
                        //    width: "120px",
                        //    title: __('该商品SKU库'),
                        //    table: table,
                        //    events: Table.api.events.operate,
                        //    operate: false,
                        //    buttons: [
                        //        {
                        //            name: 'detail',
                        //            text: __('该商品SKU库'),
                        //            title: __('该商品SKU库'),
                        //            extend: 'data-area=\'["90%","90%"]\'',
                        //            classname: 'btn btn-sm btn-success btn-dialog',
                        //            icon: 'fa fa-try fa-fw',
                        //            url: 'feditionorderskup/index?product_id={product_id}'
                        //        }
                        //    ],
                        //    formatter: Table.api.formatter.buttons
                        //},
                        //{
                        //    field: 'buttons',
                        //    width: "120px",
                        //    title: __('获取商品最新SKU'),
                        //    table: table,
                        //    events: Table.api.events.operate,
                        //    operate: false,
                        //    buttons: [
                        //        {
                        //            name: 'ajax',
                        //            text: __('获取商品最新SKU'),
                        //            title: __('获取商品最新SKU'),
                        //            classname: 'btn btn-sm btn-info btn-magic btn-ajax',
                        //            icon: 'fa fa-usd',
                        //            confirm: '确认更新吗？',
                        //            url: 'feditionorderquantityp/addorderproduct?product_id={product_id}',
                        //            success: function (data, ret) {
                        //                Layer.alert(ret.msg);
                        //                //刷新父级页面
                        //                // window.parent.location.reload();
                        //                //刷新当前页面
                        //                table.bootstrapTable('refresh', {});
                        //                return true;
                        //            },
                        //            error: function (data, ret) {
                        //                console.log(data, ret);
                        //                Layer.alert(ret.msg);
                        //                return false;
                        //            }
                        //        },
                        //    ],
                        //    formatter: Table.api.formatter.buttons
                        //},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});